/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_layer3_data_services.h

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	Xi.Wang		2018/9/5	Create
*/

#ifndef _LAYER3_DATA_SERVICES_ME_H_
#define _LAYER3_DATA_SERVICES_ME_H_
#include "omci_adpt_common.h"

#define  OMCI_LAYER3_STR_BUFF_SIZE   32
#define  OMCI_LAYER3_ATR_BUFF_SIZE   16
#define  OMCI_LAYER3_VAL_BUFF_SIZE   8

#define MAX_IPHOST_WAN_NUM		(2)
#define WAN_SRV_TR069_STR     "TR069"  
#define WAN_SRV_VOICE_SRV     "VOICE"

#define MAX_WAN_PATH_LENTH		(32)
#define MAX_WAN_ATTR_LENTH		(32)


extern char tr69wan[];

typedef struct __pthreadIPHostArgType{
		uint16_t tranCorrelatId;
		uint16_t meClassId;
		uint8_t msgFormat;		//0x0A:baseline format   0X0B:extended format
		uint32_t addr;
		uint8_t testType;
}pthreadIPHostArgType;

enum wanIFType{
	WAN_IF_TYPE_IP_ADDR=0,
	WAN_IF_TYPE_NETMASK,
	WAN_IF_TYPE_GATEWAY,
	WAN_IF_TYPE_PRI_DNS,
	WAN_IF_TYPE_SEC_DNS,
	WAN_IF_TYPE_MAC_ADDR,
	WAN_IF_TYPE_ISP,
	WAN_IF_TYPE_VLANID,
	WAN_IF_TYPE_DOT1P,
	WAN_IF_TYPE_LINKMODE,
	WAN_IF_TYPE_SVC_LIST,
	WAN_IF_TYPE_MAX,
};

enum pppoeIFType{
    PPPOE_IF_TYPE_ENCAP = 0,
    PPPOE_IF_TYPE_LINKMODE,
    PPPOE_IF_TYPE_PPPGETIP,
    PPPOE_IF_TYPE_CONNECTION,
    PPPOE_IF_TYPE_USERNAME,
    PPPOE_IF_TYPE_PASSWORD,
    PPPOE_IF_TYPE_ISP,
    PPPOE_IF_TYPE_NATENABLE,
    PPPOE_IF_TYPE_DHCPEN,
    PPPOE_IF_TYPE_PPPUNIT,
    PPPOE_IF_TYPE_IFNAME,
    PPPOE_IF_TYPE_CONNECTIONERROR,
    PPPOE_IF_TYPE_CLOSEIFIDLE,
    PPPOE_IF_TYPE_AUTHEN,
    PPPOE_IF_TYPE_SVC_LIST,
    PPPOE_IF_TYPE_SRVNAME,
    PPPOE_IF_TYPE_MAX
};

enum wanServiceListType{
    WAN_SERVICELIST_TR069 = 0,
    WAN_SERVICELIST_VOICE,
    WAN_SERVICELIST_MAX
    
};

typedef struct OMCI_IPHOST_INFO_s
{
	uint8_t 	change; /* 0 -- no change ; 1 -- changed ; 2 -- deleted*/
    uint16_t 	attr_mask;
    char	path[MAX_WAN_PATH_LENTH];
    char	val[WAN_IF_TYPE_MAX][MAX_WAN_ATTR_LENTH];
}OMCI_IPHOST_INFO_t;


#define OMCI_CHECK_IPHOST_ID(id)  \
		if(id >= MAX_IPHOST_WAN_NUM) \
		{\
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"iphost %d exceed max num return\n",id);\
			return -1;\
		}
	
#define OMCI_CHECK_TYPE_ID(type)  \
		if(type >= WAN_IF_TYPE_MAX) \
		{\
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"Attr type id %d exceed max num return\n",type);\
			return -1;\
		}


typedef struct omciIPhostWanInfo_s
{
	char ipAddr[OMCI_LAYER3_STR_BUFF_SIZE];
	char netMask[OMCI_LAYER3_STR_BUFF_SIZE];
    char geteWay[OMCI_LAYER3_STR_BUFF_SIZE];
    char priDNS[OMCI_LAYER3_STR_BUFF_SIZE];
    char secDNS[OMCI_LAYER3_STR_BUFF_SIZE];
	char MACAdd[OMCI_LAYER3_STR_BUFF_SIZE];
	char isp[OMCI_LAYER3_VAL_BUFF_SIZE];
    char vlanId[OMCI_LAYER3_VAL_BUFF_SIZE];
    char pBit[OMCI_LAYER3_VAL_BUFF_SIZE];
    char linkMode[OMCI_LAYER3_STR_BUFF_SIZE];
    char serviceList[OMCI_LAYER3_STR_BUFF_SIZE];
    char ifNode[OMCI_LAYER3_STR_BUFF_SIZE];
    char iphostId[OMCI_LAYER3_VAL_BUFF_SIZE];
}omciIPhostWanInfo_t; 


typedef struct omciIPhostChkTimer_s
{
    int wanType;
    uint16_t iphostId;
}omciIPhostChkTimer_t; 

typedef struct omciIPhostCheckWanInfo_s
{
    int wanType;
    char IPHostType[OMCI_LAYER3_STR_BUFF_SIZE];
    char IPHostWan[OMCI_LAYER3_STR_BUFF_SIZE];
    char ifName[OMCI_LAYER3_STR_BUFF_SIZE];
    uint16_t IPHostIstId;
    char IPHostTypeNow[OMCI_LAYER3_STR_BUFF_SIZE];
    char wanIf[OMCI_LAYER3_STR_BUFF_SIZE];
    omciIPhostWanInfo_t * oldAttr;
    int  ifSetByOMCI;
    int  ifCreateByOMCI;
}omciIPhostCheckWanInfo_t;

typedef struct omciPPPoECfgAttrInfo_s{
    char enable;
    char path[OMCI_LAYER3_STR_BUFF_SIZE];
    uint16_t iphostId;
    char NATMode;
    char AuthVal;
    char connectMode;
    uint16_t releaseTime;
    char username[25];
    char password[25];
    uint16_t userNameStrTP;
    uint16_t serviceStrTP;
}omciPPPoECfgAttrInfo_t;


typedef enum
{
	E_WAN_SVC_TYPE_TR069        = 0x0,
    E_WAN_SVC_TYPE_VOICE        = 0x1,
    E_WAN_SVC_TYPE_MAX          = 0x2
}wan_svc_type;

typedef struct OMCI_IPHOST_WAN_RCD_s
{
    char              valid;
    char              change;
    uint16_t          iphostId;
    char              path[MAX_WAN_PATH_LENTH];
    char              attr_val[WAN_IF_TYPE_MAX][MAX_WAN_ATTR_LENTH];
}OMCI_IPHOST_WEB_RCD_t;


int omciFinishSetWanInfo(void);
int setWanInfo(int type ,uint16_t IPHostIstId, char* buf);
void omci_wan_clear_change(uint16_t IPHostIstId);
extern OMCI_IPHOST_INFO_t g_iphost_wan[MAX_IPHOST_WAN_NUM];
extern int commitWanTimer;

extern OMCI_IPHOST_WEB_RCD_t g_web_rcd_info[E_WAN_SVC_TYPE_MAX];
extern uint8_t svclist_is_tr69(uint16_t IPHostId);
extern int omci_wan_init_web_rcd(void);
extern void omci_update_wan_rcd_info(void);
extern int omci_wan_convert_to_attr(int type, char* buf, char* attr);
extern void omci_link_to_web(uint16_t IPHostIstId,char* srvlist);
extern void omci_wan_dump_web_rcd(void);
extern void omci_wan_dump_iphost_wan(void);
extern int omci_wan_recovery_web(uint32_t svc_type);

extern omciPPPoECfgAttrInfo_t omciPPPoEInfo;
extern char g_pppoe_wan[PPPOE_IF_TYPE_MAX+1][OMCI_LAYER3_STR_BUFF_SIZE];

//9.4.1: IP host config data

extern omci_attr_dscp_t omci_attr_ip_host_cfg_op[];
extern omci_me_func_t omci_me_ip_host_cfg_op;
extern omci_attr_t omci_ip_host_cfg_attr;

extern omci_attr_dscp_t omci_attr_ip_host_pm_his_op[];
extern omci_me_func_t omci_me_ip_host_pm_his_op;
extern omci_attr_t omci_ip_host_pm_his_attr;

extern omci_attr_dscp_t omci_attr_tcp_udp_config_op[];
extern omci_me_func_t omci_me_tcp_udp_config_op;
extern omci_attr_t omci_tcp_udp_config_attr;

extern omci_attr_dscp_t omci_attr_tcp_udp_pm_his_op[];
extern omci_me_func_t omci_me_tcp_udp_pm_his_op;
extern omci_attr_t omci_tcp_udp_pm_his_attr;

extern omci_attr_dscp_t omci_attr_PPPoE_wan_config_op[];
extern omci_me_func_t omci_me_PPPoE_wan_config_op;
extern omci_attr_t omci_PPPoE_wan_cfg_attr_attr;

int get_iphost_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag);
int get_tcp_udp_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag);

int omci_me_iphost_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info);
int omci_me_tcp_udp_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info);





#endif

